Retrieving the MPV Tidy Dataset

mpv_data =
  read_csv("./data/mpv_final.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   age = col_double(),
##   gender = col_character(),
##   race = col_character(),
##   police_dept = col_character(),
##   disposition = col_character(),
##   year = col_double(),
##   month = col_double(),
##   day = col_double(),
##   city = col_character(),
##   state = col_character(),
##   county = col_character(),
##   cause_of_death = col_character(),
##   criminal_charges = col_character(),
##   symptoms_of_mental_illness = col_character(),
##   lat = col_double(),
##   lng = col_double()
## )

Year Leaflet – with city and police dept in the label

pal <- colorNumeric(
  palette = "viridis",
  domain = mpv_data$year)


mpv_data %>% 
  drop_na() %>% 
  mutate(
    lab = str_c("City: ", city, "<br>Police Department: ", police_dept)) %>%
  leaflet() %>% 
  addTiles() %>% 
  setView(-98.483330, 38.712046, zoom = 4) %>% 
  addLegend("bottomright", pal = pal,
            values = ~year,
            title = "Year",
            labFormat = labelFormat(big.mark = ""),
            opacity = 1) %>% 
  addCircleMarkers(
    ~lng, ~lat,
    color = ~pal(year),
    radius = 0.5,
    popup = ~lab)

Age Leaflet – with symptoms of mental illness and whether officer was charged as label

pal <- colorNumeric(
  palette = "viridis",
  domain = mpv_data$age)


mpv_data %>% 
  drop_na() %>% 
  mutate(
    lab = str_c("Age: ", age,
                "<br>Symptoms of Mental Illness: ", symptoms_of_mental_illness,
                "<br>Charges on the Police: ", criminal_charges)) %>%
  leaflet() %>% 
  addTiles() %>% 
  setView(-98.483330, 38.712046, zoom = 4) %>% 
  addLegend("bottomright", pal = pal,
            values = ~age,
            title = "Age",
            opacity = 1) %>% 
  addCircleMarkers(
    ~lng, ~lat,
    color = ~pal(age),
    radius = 0.5,
    popup = ~lab)

USA data

usa_protest = read_csv("./data/usa_tidy.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   year = col_double(),
##   month = col_double(),
##   day = col_double(),
##   event_type = col_character(),
##   sub_event_type = col_character(),
##   state = col_character(),
##   county = col_character(),
##   city = col_character(),
##   latitude = col_double(),
##   longitude = col_double(),
##   fatalities = col_double()
## )
pal <- colorNumeric(
  palette = "viridis",
  domain = usa_protest$fatalities)

usa_protest %>%
  mutate(
    lab = str_c("City: ", usa_protest$city, "<br>Type of Protest: ", usa_protest$event_type)) %>%
  leaflet() %>% 
  addTiles() %>% 
  setView(-98.483330, 38.712046, zoom = 4) %>% 
  addLegend("bottomright", pal = pal,
            values = usa_protest$fatalities,
            title = "Fatalities",
            labFormat = labelFormat(big.mark = ""),
            opacity = 1) %>% 
  addCircleMarkers(
    ~longitude, ~latitude,
    color = ~pal(usa_protest$fatalities),
    radius = 0.5,
    popup = ~lab)
pal <- colorNumeric(
  palette = "viridis",
  domain = usa_protest$month)

usa_protest %>%
  mutate(
    lab = str_c("City: ", usa_protest$city, "<br>Type of Protest: ", usa_protest$event_type)) %>%
  leaflet() %>% 
  addTiles() %>% 
  setView(-98.483330, 38.712046, zoom = 4) %>% 
  addLegend("bottomright", pal = pal,
            values = usa_protest$month,
            title = "Month",
            labFormat = labelFormat(big.mark = ""),
            opacity = 1) %>% 
  addCircleMarkers(
    ~longitude, ~latitude,
    color = ~pal(usa_protest$month),
    radius = 0.5,
    popup = ~lab)

ACS Income maps

Police Killings by Income Class

build_df =
  read_csv("./data/build_df.csv") %>% 
  mutate(
    income_class = fct_relevel(income_class, "Very High", "High", "Middle", "Low", "Very Low")
  )
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   gender = col_character(),
##   race = col_character(),
##   police_dept = col_character(),
##   disposition = col_character(),
##   city = col_character(),
##   state = col_character(),
##   county = col_character(),
##   cause_of_death = col_character(),
##   criminal_charges = col_character(),
##   symptoms_of_mental_illness = col_character(),
##   state_name = col_character(),
##   id = col_character(),
##   income_class = col_character()
## )
## i Use `spec()` for the full column specifications.
factpal <- colorFactor("RdYlGn", build_df %>% pull(income_class))

build_df %>% 
  drop_na() %>% 
  mutate(
  pop = str_c("Cause of Death: ", cause_of_death,
              "<br>Police Dept: ", police_dept,
              "<br>Age: ", age, 
              "<br>Year: ", year,
              "<br>Symptoms of Mental Illness: ", symptoms_of_mental_illness)) %>%
  leaflet() %>% 
  addProviderTiles(providers$CartoDB.Positron) %>% 
  addLegend("bottomright", pal = factpal,
            values = ~as.factor(income_class),
            title = "Income Class",
            labFormat = labelFormat(big.mark = ""),
            opacity = 1) %>%
  addCircleMarkers(
    ~lng, ~lat,
    color = ~factpal(income_class),
    radius = 0.5,
    popup = ~pop
    )

Protest Data by Income Class

protest_income_df =
  read_csv("./data/protest_income_df.csv") %>% 
  mutate(
    income_class = fct_relevel(income_class, "Very High", "High", "Middle", "Low", "Very Low")
  )
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   event_type = col_character(),
##   sub_event_type = col_character(),
##   state = col_character(),
##   county = col_character(),
##   city = col_character(),
##   id = col_character(),
##   income_class = col_character()
## )
## i Use `spec()` for the full column specifications.
factpal2 <- colorFactor("BuGn", protest_income_df %>% pull(income_class))

protest_income_df %>% 
  drop_na() %>% 
  mutate(
  pop1 = str_c("City: ", city, "<br>Event Type: ", 
               sub_event_type, "<br>Year: ", year, "<br>Fatalities: ", fatalities)) %>%
  leaflet() %>% 
  addProviderTiles(providers$CartoDB.Positron) %>% 
  addLegend("bottomright", pal = factpal2,
            values = ~as.factor(income_class),
            title = "Income Class",
            labFormat = labelFormat(big.mark = ""),
            opacity = 1) %>%
  addCircleMarkers(
    ~longitude, ~latitude,
    color = ~factpal2(income_class),
    radius = 0.5,
    popup = ~pop1
    )